<template>
  <div class="home">
    <Home-Header />
    <Home-Swiper :list="swiperList" />
    <HomeIcons :list="iconList" />
    <HomeRecommend :list="recommendList" />
    <HomeWeekend :list="weekendList" />  
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
    name:'Home',
    components:{
      HomeHeader,
      HomeSwiper,
      HomeIcons,
      HomeRecommend,
      HomeWeekend
    },
    data () {
      return {
        lastCity: '',
        swiperList:[],
        iconList:[],
        recommendList:[],
        weekendList:[]
      }
    },
    computed: {
    ...mapState(['city'])
    },
    methods: {
      getHomeInfo () {
        // axios.get('/static/mock/index.json?city=' + this.city)
        axios.get('/mock/index' )

        .then(this.getHomeInfoSucc)
      },
      getHomeInfoSucc (res) {
        res = res.data.data
        if (res.ret && res.data) {
          const data = res.data
          //  console.log('res',res);
          this.swiperList = res.data.swiperList
          this.iconList = res.data.iconList
          this.recommendList = res.data.recommendList
          this.weekendList = res.data.weekendList
          
        }
      }
    },
    mounted () {
      this.lastCity = this.city
      this.getHomeInfo()
    },
    activated () {
      if (this.lastCity !== this.city) {
        this.lastCity = this.city
        this.getHomeInfo()
      }
    }
}
</script>

<style>

</style>